package me.yricky.alia.ui

import androidx.compose.ui.geometry.Offset
import me.yricky.alia.data.base.Coord
import me.yricky.alia.data.shape.Box

/**
 * @author Yricky
 * @date 2022/1/27
 */
data class FBox(
    val lt: Offset,
    val rb: Offset
)

val FBox.width:Float get() = rb.x-lt.x
val FBox.height:Float get() = rb.y-lt.y
val FBox.center: Offset get() = Offset((lt.x+rb.x)/2,(lt.y+rb.y)/2)
fun FBox.contains(coord: Coord):Boolean{
    return lt.x < coord.x && rb.x > coord.x && lt.y < coord.y && rb.y > coord.y
}

fun FBox.isOverlap(box:Box):Boolean{
    return (lt.x < box.rb.x && rb.x > box.lt.x) && (lt.y < box.rb.y && rb.y > box.lt.y)
}

fun FBox.toBox() = Box(
    Coord(lt.x.toInt(),lt.y.toInt()),
    Coord(rb.x.toInt(),rb.y.toInt())
)

fun FBox.centerZoom(index:Float):FBox{
    return center.let{
        FBox(
            Offset(it.x-width/2/index,it.y-height/2/index),
            Offset(it.x+width/2/index,it.y+height/2/index),
        )
    }
}